
def maxHappyTime(books):
    n = len(books)
    dp = [0] * n  # dp[i]表示阅读到第i本书时的最大快乐时间

    # 初始化第一本书的最大快乐时间
    dp[0] = books[0]

    for i in range(1, n):
        time = i + 1  # 阅读第i本书所需的时间
        happy_time = time * books[i]  # 第i本书的快乐时间

        # 尝试从之前的状态转移得到更大的快乐时间
        for j in range(i):
            prev_time = i - j  # 阅读第j本书到第i本书所需的时间
            prev_happy_time = prev_time * books[i]  # 第j本书到第i本书的快乐时间
            dp[i] = max(dp[i], dp[j] + prev_happy_time)

        # 考虑不阅读第i本书的情况
        dp[i] = max(dp[i], dp[i-1])

    return dp[n-1]  # 返回最大的快乐时间


books = [4, 3, 2]
result = maxHappyTime(books)
print("最大快乐时间为:", result)
